class CategoryController {
	def scaffold = true
    
    def listJob = {
    	def result = [:]
    	if (params.category) {
    		result.category = Category.findByName(params.category)
    	} else {
    		result.recentJobs = Job.list([max:7, sort:'dateCreated', order:'desc'])
    		result.allCategories = Category.list(sort:'displayOrder')
    	}
    	return result
    }
    
    def search = {
    	def result = [:]

		def category = null
		
    	if (params.category) {
    		result.category = Category.findByName(params.category)
    	}
    	def q = "%${params.q}%"
    	def c = Job.createCriteria()
    	result.jobs = c.list {
    			if (result.category) {
    				eq('category', result.category)
    			}
				or {
					ilike('title', q)
					ilike('details',q)
					ilike('companyName',q)
					location {
						ilike('value', q)
					}
				}
    		}     	
    	
    	return result
    }
}
